﻿namespace Harness.Recording.SourceCodeFormatters
{
    using System.Collections.Generic;
    using System.Text;

    public class VisualBasicSourceCodeFormmater : ISourceCodeFormatter
    {
        public string StartupCode()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Dim harness");
            sb.AppendLine("Set harness = CreateObject(\"Harness\")");

            return sb.ToString();
        }

        public string Format(string cmd, IEnumerable<string> args)
        {
            List<string> list = new List<string>();

            list.Add(string.Format("\"{0}\"", cmd));

            using (IEnumerator<string> iterator = args.GetEnumerator())
            {
                while (iterator.MoveNext())
                {
                    if (!string.IsNullOrWhiteSpace(iterator.Current))
                    {
                        list.Add(string.Format("\"{0}\"", iterator.Current.Replace("\"", "\\\"")));
                    }
                }
            }

            return string.Format("harness.Command {0}", string.Join(",", list));
        }
    }
}
